<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="event" class="mtyan.Event"/>
<jsp:setProperty name="event" property="*"/>
<jsp:useBean id="comment" class="mtyan.Comment"/>
<jsp:setProperty name="comment" property="*"/>
<jsp:useBean id="events" class="mtyan.Events"/>
<jsp:useBean id="connector" class="mtyan.MySQLConnector"/>
<%
	String action = request.getParameter("action");
	if (action != null && action.equals("addEvent")) {
		events.add(event);
	} else if (action.equals("addComment")){
		events.addComment(comment);
	}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Events</title>
</head>
<body>
<%
List<List<String>> eventArray = connector.executeQuery("*", 5,
		"event", null);
	for (List<String> eventRow : eventArray) {
		out.print("<div style=\"border:#dddddd solid 1px; padding:10px; width:80%; margin:5px\">");
		out.print("<span style=\"font-style:italic\">"
				+ eventRow.get(1) + "</span><br/>");
		out.print(eventRow.get(2)+"<br/>");
		out.print("Begins at: " + eventRow.get(3) + "<br/>");
		out.print("Ends at: " + eventRow.get(4) + "<br/>");
		out.print("Participants: <br/>");
		List<List<String>> participants = connector.executeQuery("firstname, lastname", 2, "user", "id IN (SELECT id_user FROM event_user WHERE id_event=" + eventRow.get(0) + ")");
		for (List<String> participant : participants){
			out.print(participant.get(0)+" "+participant.get(1)+"<br/>");
		}
%>
	<form method="post" action="ControllerServlet?action=showAddComment&eventId=<%= eventRow.get(0) %>">
	<INPUT TYPE="SUBMIT" value="Add Comment"/>
	</form>
<%		
		out.print("</div>");
	}
%>
<form method="post" action="ControllerServlet?action=showAddEvent">
<INPUT TYPE="SUBMIT" value="Add Event"/>
</form>
</body>
</html>